-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(web): replace NetworkClient with queries #1519
Conversation
9f88be2
to
89a779c
Compare
Needed for building HTML ids without spaces from networks SSID since spaces into an `aria-labelledby` attr are used as ids separator.
Keeping only the ssid, if any, from previous data stored in the query since it's the unique data needed to allow the needsAuth update performed on a failed device event.
It's no longer needed after previous changes improving the filtering and mapping.
And include few code style changes done by prettier.
* Support for needsAuth flag. * Support for adding or updating a connection, depending on the network settings. * Fixed unit tests.
Migrating the file from jsx to tsx because the ConnectionsTable component was already migrated to TypeScript.
|
||
const HIDDEN_NETWORK = Object.freeze({ hidden: true }); | ||
type HiddenNetwork = { hidden: boolean }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type quite smell for me as I expect that hidden network contain more entries...why WifiNetwork cannot be used? or maybe instead of const variable method that do that simple check for hidden value on common WifiNetwork type can be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me revisit this and see how we can improve it. I think yesterday we added the hidden attribute to WifiNetwork type, which was not the case before and probably the reason why this weird, ad-hoc type is here.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see now. WifiNetwork is an AccessPoint plus WifiNetworkStatus plus other optional values like hidden
. So, HIDDEN_NETWORK cannot be a WifiNetwork sinde it does belong to none access point. A bit lost here, so I prefere to wait until @teclator can have a look.
type SelectedWifi = { | ||
ssid?: string; | ||
hidden?: boolean; | ||
needsAuth?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so selected wifi can be empty? it looks kind of strange. I expect that at least ssid is mandatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that strange. You can connect to a hidden Wi-Fi network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is strange for me as hidden network has SSID. The difference is that AP does not broadcast that SSID, so it is not visible when you scan list of available network. But to be able to connect to it, you need to know SSID. Just try it with your NM applet, when you want to connect to hidden network you have to provide its name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know how hidden network works :) But the problem is that this is a "UI query" for keeping which network is/was selected by the user in order to show the proper information about it: the connection form or its configuration/state and actions.
But the user could select a "hidden network", for which the UI does not know the SSID in advance. That's why the ssid here is optional. Maybe a matter of naming or a matter or typing improvement (I'm just landing in the typed languages world :P)
How would you improve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least document that info in the type as it is confusing for reader. So mention that for hidden network ssid is not known in advance. I am not sure if you can have something in ts like that hidden is true or ssid is specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if you can have something in ts like that hidden is true or ssid is specified.
Interesting point. I'm going to see if that it's possible. Thanks a ton!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh! Actually is a bit more tricky than I though because I forgot to mention a small detail in previous explanations: we're updating the information in the query in a moment in which we don't know the ssid but only that the authentication failed. So, we assumed that authentication failed for the selected connection. See https://github.com/openSUSE/agama/pull/1519/files#diff-f1b1879261cce23d74bb1716c65fbbcb487ee658acf074133fc6d6def7288736R223-R263
So, to make it work without TypeScript complaints the changes would be something like
diff --git a/web/src/queries/network.ts b/web/src/queries/network.ts
index 00754d6d..d8fecc7a 100644
--- a/web/src/queries/network.ts
+++ b/web/src/queries/network.ts
@@ -193,16 +193,25 @@ const useSelectedWifi = (): { ssid?: string; needsAuth?: boolean; hidden?: boole
};
const useSelectedWifiChange = () => {
- type SelectedWifi = {
- ssid?: string;
- hidden?: boolean;
- needsAuth?: boolean;
+ type VisibleWifi = {
+ ssid: string;
+ hidden?: false | never;
};
+ type HiddenWifi = {
+ ssid?: never;
+ hidden: true;
+ };
+
+ type KnownWifi = VisibleWifi & { needsAuth?: boolean };
+
+ type SelectedWifi = KnownWifi | HiddenWifi;
+
const queryClient = useQueryClient();
const mutation = useMutation({
- mutationFn: async (data: SelectedWifi): Promise<SelectedWifi> => Promise.resolve(data),
+ mutationFn: async (data: Partial<SelectedWifi>): Promise<Partial<SelectedWifi>> =>
+ Promise.resolve(data),
onSuccess: (data: SelectedWifi) => {
queryClient.setQueryData(["wifi", "selected"], (prev: SelectedWifi) => ({
ssid: prev.ssid,
On one hand, from the typing POV would be more clear that a hidden wifi is unknown until the user enters the ssid and became it in a KnownWifi. On the other hand... although safer and robust code looks a bit complicated. What do you think?
finished with code review. Manual test is currently ENOTIME. |
Prepare for releasing Agama 10· * #1263 * #1330 * #1407 * #1408 * #1410 * #1411 * #1412 * #1416 * #1417 * #1419 * #1420 * #1421 * #1422 * #1423 * #1424 * #1425 * #1428 * #1429 * #1430 * #1431 * #1432 * #1433 * #1436 * #1437 * #1438 * #1439 * #1440 * #1441 * #1443 * #1444 * #1445 * #1449 * #1450 * #1451 * #1452 * #1453 * #1454 * #1455 * #1456 * #1457 * #1459 * #1460 * #1462 * #1464 * #1465 * #1466 * #1467 * #1468 * #1469 * #1470 * #1471 * #1472 * #1473 * #1475 * #1476 * #1477 * #1478 * #1479 * #1480 * #1481 * #1482 * #1483 * #1484 * #1485 * #1486 * #1487 * #1488 * #1489 * #1491 * #1492 * #1493 * #1494 * #1496 * #1497 * #1498 * #1499 * #1500 * #1501 * #1502 * #1503 * #1504 * #1505 * #1506 * #1507 * #1508 * #1510 * #1511 * #1512 * #1513 * #1514 * #1515 * #1516 * #1517 * #1518 * #1519 * #1520 * #1522 * #1523 * #1524 * #1525 * #1526 * #1527 * #1528 * #1529 * #1530 * #1531 * #1532 * #1533 * #1534 * #1535 * #1536 * #1537 * #1540 * #1541 * #1543 * #1544 * #1545 * #1546 * #1547 * #1548 * #1549 * #1550 * #1552 * #1553 * #1554 * #1555 * #1556 * #1557 * #1558 * #1559 * #1560 * #1562 * #1563 * #1565 * #1566 * #1567 * #1568 * #1569 * #1570 * #1571 * #1572 * #1573 * #1574 * #1575 * #1576 * #1577 * #1578 * #1579 * #1580 * #1581 * #1583 * #1584 * #1585 * #1586 * #1587 * #1588 * #1589 * #1590 * #1591 * #1592 * #1593 * #1596 * #1597 * #1598 * #1600 * #1602 * #1605 * #1606 * #1607 * #1608 * #1610 * #1611 * #1612 * #1613 * #1614 * #1619 * #1620 * #1621
Adapt the network management code to use queries instead of NetworkCient. Related to #1439.
Additionally, starts migrating the code to TypeScript and fixes bugs found by the type system.
Reviewers, please note that this ended up being a rather long PR, reason why is better to not only review the code but also to do manual testing if possible. Take your time, but any issue out of the scope of state management / queries migration should be reported as a new issue to be addressed in a new PBI.
Notes for creating follow-up work,
"error": "Network system error: Network state error: Connection '<ssid>' already exists"
when connecting to hidden network that previously failed. In short, we should either, to drop the configuration created for a failed { hidden: true } connection or to implement a mechanism to know that such a configuration already exists and performs an update instead of add.FIXME: IPv6 is not supported yet.
comments